package com.crm.config;

import com.crm.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @version 1.0
 * @author: CRM_SYSTEM
 * @date: 2022/3/29 21:16
 * @Description:
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

  @Override
  public void addInterceptors(InterceptorRegistry registry) {

    //定义排除swagger访问的路径配置
    String[] swaggerExcludes=new String[]{"/swagger-ui.html","/swagger-resources/**","/webjars/**"};
    registry.addInterceptor(authenticationInterceptor())
        .addPathPatterns("/**")
    .excludePathPatterns(swaggerExcludes)
    ;    // 拦截所有请求，通过判断是否有 @PassToken 注解 决定是否需要验证
  }

  @Bean
  public AuthenticationInterceptor authenticationInterceptor() {
    return new AuthenticationInterceptor();
  }
}
